<template>
  <div>
    <el-container>
      <el-header class="header" style="height: 95px ">APE 后台管理系统</el-header>
      <el-container style="height: 680px">
        <el-aside width="200px">
          <navbar :menus="menus" :collapse="isCollapse"></navbar>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import routes from "../router/routes";
import Navbar from "./Navbar/index";

export default {
  components: {
    Navbar,
  },
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    handleCollapse() {
      console.log("这是啥");
      this.isCollapse = !this.isCollapse;
    },
    resolveForMenu(arr, parentPath = "") {
      let newArr = [];
      // 遍历传入的arr数组

      // 处理上级路径

      //判断当前对象（路由）是否具有children节点，如果有，递归处理children节点后，
      //将当前节点加入数组，，如果没有则直接将当前节点加入新数组

      //返回最后处理完成的数组

      arr.forEach((route) => {
        parentPath =
          parentPath && parentPath.lastIndexOf("/") !== parentPath.length - 1
            ? parentPath + "/"
            : parentPath;
        // console.log(parentPath);
        let obj = Object.assign({}, route);
        obj.path = parentPath + obj.path;
        if (obj.children && obj.children.length > 0) {
          obj.children = this.resolveForMenu(obj.children, obj.path);
        }
        // 如果某路由元数据中，设置为当前路由为隐藏，则当前路由将不作为导航菜单显示，只将其children加入到菜单数组
        if (obj.meta.hidden) {
          // 如果存在children属性，那么继续处理下（将所有子节点提升并加入到返回数组），反之不作处理
          if (obj.children && obj.children.length > 0) {
            obj.children.forEach((item) => {
              let tmp = Object.assign({}, item);
              newArr.push(tmp);
            });
          }
        } else {
          newArr.push(obj);
        }
      });

      return newArr;
    },
  },

  computed: {
    menus() {
      var arr = this.resolveForMenu(routes);
      return arr;
    },
  },
};
</script>

<style >

.el-header {
  background-color:#FFF !important ;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
  font-size: 14px;
}

.el-aside {
  background-color:#333;
  color: #333;
  /* text-align: center; */
  line-height: 200px;
  height: 100% !important;
  width: 200px !important;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  /* text-align: center; */
  line-height: 35px;
  height: 100vh;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-menu-item{
  background-color: white;
}
.header{
  align-content: center;
  justify-content: center;
  flex: auto;
  size: 50px;
}
</style>